package filters;

import interfaces.IMap;

public class SharpenFilter implements IFilter
{
	float SMap[][];
	
    //===========================================================================
    public SharpenFilter()
    {
    	SMap = new float[5] [5];
        SMap[0] [0] = -1;
        SMap[1] [0] = -1;
        SMap[2] [0] = -1;
        SMap[3] [0] = -1;
        SMap[4] [0] = -1;

        SMap[0] [1] = -1;
        SMap[1] [1] = -2;
        SMap[2] [1] = -2;
        SMap[3] [1] = -2;
        SMap[4] [1] = -1;
        
        SMap[0] [2] = -1;
        SMap[1] [2] = -2;
        SMap[2] [2] = 40;
        SMap[3] [2] = -2;
        SMap[4] [2] = -1;
        
        SMap[0] [3] = -1;
        SMap[1] [3] = -2;
        SMap[2] [3] = -2;
        SMap[3] [3] = -2;
        SMap[4] [3] = -1;
        
        SMap[0] [4] = -1;
        SMap[1] [4] = -1;
        SMap[2] [4] = -1;
        SMap[3] [4] = -1;
        SMap[4] [4] = -1;

    }
    //===========================================================================
    public int ApplyFilter(int Px,int Py, IMap map)
    {
    	int sum=0;
        
    	for (int y = -2; y < 3; y++)
            for (int x = -2; x < 3; x++)
            {
            	int xf=x + 2;
            	int yf=y + 2;
            	float C = map.Get(Px + x,Py + y);
            	sum += (int)(C * SMap[xf][yf]);
            	
            }
        sum=sum/8;
        if (sum > 255)
            return (int)255;
        if (sum < 0)
            return (int)0;
        return (int)(sum);
    }
    //===========================================================================

}